package com.city.cmsservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.city.cmsservice.entity.CrmBanner;
import com.city.cmsservice.service.CrmBannerService;
import com.city.commonutils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author city
 * @since 2020-09-20
 *
 * 编写：
 * 前台数据展示，搜索
 * 后台数据库操作，crud，后台管理系统的前端不写了，更之前的教师课程的操作差不多
 *
 * 后台
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;

    //分页查询
    @GetMapping("pageBanner/{page}/{limit}")
    public Result pageBanner(@PathVariable Long page,@PathVariable Long limit){
        Page<CrmBanner> pageBanner=new Page<>(page,limit);
        crmBannerService.page(pageBanner,null);
        return Result.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }

    @PostMapping("addBanner")
    public Result addBanner(@RequestParam CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return Result.ok();
    }

    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id){
        crmBannerService.removeById(id);
        return Result.ok();
    }

    @PutMapping("update")
    public Result update(@RequestParam CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return Result.ok();
    }

    @GetMapping("get/{id}")
    public Result get(@PathVariable String id){
        CrmBanner byId = crmBannerService.getById(id);
        return Result.ok().data("item",byId);
    }
}